package com.hsh.utils.sort;

/**
 * Created by root on 17-4-21.
 */
public class ArraySortUtils {

    public static int[] bubbleSort(int[] data) {
        for (int i = 0; i < data.length - 1; i++) {
            for (int j = 0; j < data.length - i - 1; j++) {
                if (data[j] > data[j + 1]) {
                    swap(j, j + 1, data);
                }
            }
        }
        return data;
    }

    public static void swap(int idx1, int idx2, int[] data) {
        data[idx1] = data[idx1] ^ data[idx2];
        data[idx2] = data[idx1] ^ data[idx2];
        data[idx1] = data[idx1] ^ data[idx2];
    }

    public static void main(String[] args) {
        int[] data = {1, 3, 343, 33, 4343, 3431234, 4343, 1, 2};
        int[] ints = bubbleSort(data);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }
}
